package com.k2data.k2app.service;

import com.k2data.k2app.domain.WarningRecord;
import com.k2data.k2app.mapper.WarningRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Author cuilibo@k2data.com.cn
 * @Date 18-4-18 下午5:28.
 */
@Service
public class WarningRecordService {
    @Autowired
    private WarningRecordMapper warningRecordMapper;

    public List<WarningRecord> list() {
        List<WarningRecord> warningRecords = warningRecordMapper.selectAll();
        return warningRecords;
    }

    public void add(WarningRecord record) {
        warningRecordMapper.insert(record);
    }

    public WarningRecord getLastOne() {
        Example example = new Example(WarningRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("status","fault");
        example.setOrderByClause("warning_time limit 1");
        List<WarningRecord> warningRecords = warningRecordMapper.selectByExample(example);
        if (warningRecords.size()>0)
            return warningRecords.get(0);
        return null;
    }

}
